//
//  LSForgetPasswardVController.m
//  LookScore
//
//  Created by wr on 2017/12/16.
//  Copyright © 2017年 ChongQingXunTiCompany. All rights reserved.
//

#import "LSForgetPasswardVController.h"
#import "JKCountDownButton.h"
#import "LSResetPasswardVController.h"
#import "NSString+JKNormalRegex.h"
#import "LSHttpEnclosureTool.h"
#import "MBProgressHUD+MJ.h"

@interface LSForgetPasswardVController ()

@property (weak, nonatomic) IBOutlet UITextField *phoneTF;
@property (weak, nonatomic) IBOutlet UITextField *verificationTF;
@property (weak, nonatomic) IBOutlet JKCountDownButton *verificationBu;
@property (weak, nonatomic) IBOutlet UIButton *sureBu;

@end

@implementation LSForgetPasswardVController
//{
//    NSString *_verificationCode;
//}


- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    self.navigationController.navigationBar.translucent = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title=@"忘记密码";

    self.phoneTF.keyboardType=UIKeyboardTypePhonePad;
    self.verificationTF.keyboardType=UIKeyboardTypeDecimalPad;
    
    [self.verificationBu setBackgroundImage:[CommonClass getImageWithBgColor:LSSubColor7ec5fd] forState:UIControlStateNormal];
    [self.verificationBu setBackgroundImage:[CommonClass getImageWithBgColor:LSNavMainColor] forState:UIControlStateHighlighted];
    
    [self.sureBu setBackgroundImage:[CommonClass getImageWithBgColor:LSSubColor7ec5fd] forState:UIControlStateNormal];
    [self.sureBu setBackgroundImage:[CommonClass getImageWithBgColor:LSNavMainColor] forState:UIControlStateHighlighted];
    
   
    [self.verificationBu countDownButtonHandler:^(JKCountDownButton*sender, NSInteger tag) {
        sender.enabled = NO;
        if (![self.phoneTF.text jk_isMobileNumber]) {
            [MBProgressHUD showOnlyMessage:@"请输入有效手机号" afterDelay:1.5f];
            sender.enabled = YES;
        }else{
            
            [sender startCountDownWithSecond:60];
            
            [sender countDownChanging:^NSString *(JKCountDownButton *countDownButton,NSUInteger second) {
                NSString *title = [NSString stringWithFormat:@"剩余%zds",second];
                return title;
            }];
            [sender countDownFinished:^NSString *(JKCountDownButton *countDownButton, NSUInteger second) {
                countDownButton.enabled = YES;
                return @"重新获取";
                
            }];
            NSDictionary *validateDic=@{@"mobile":self.phoneTF.text};
            [LSHttpEnclosureTool POST:LSUserFindPwdValidate parameters:validateDic resBlock:^(id responseObject) {
                if (responseObject) {
//                    MyLog(@"code -- %@",responseObject);
//                    _verificationCode = responseObject;
                }
            }];
        }
        
    }];
    
    
}
- (IBAction)sentVerification:(id)sender {
   

}
- (IBAction)sureRevampBu:(UIButton *)sender {
//    验证成功 跳入第二步 修改密码
    if (![self.phoneTF.text jk_isMobileNumber]) {
        [MBProgressHUD showOnlyMessage:@"请输入有效手机号" afterDelay:1.5f];
    }else if (self.verificationTF.text.length<4||self.verificationTF.text.length>6){
        [MBProgressHUD showOnlyMessage:@"验证码格式错误" afterDelay:1.5f];
    }
//    else if (![self.verificationTF.text isEqualToString:_verificationCode]){
//        [MBProgressHUD showOnlyMessage:@"请输入正确验证码" afterDelay:1.5f];
//    }
    else{
        LSResetPasswardVController *resetVC=[[LSResetPasswardVController alloc]init];
        resetVC.verificationString=self.verificationTF.text;
        resetVC.mobileString=self.phoneTF.text;
        [self.navigationController pushViewController:resetVC animated:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
